/*
 * Copyright (c) 2014, Asiainfo-Linkage. All rights reserved.
 * Asiainfo-Linkage PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package edu.w106.platform.http;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p><b>标题：</b>HttpResponse.</p>
 *
 * <p><b>描述：</b></p>
 *
 * <p><b>版权：</b>Copyright (c) 2014 亚信联创</p>
 *
 * <p><b>工程：</b>platform-mc</p>
 *
 * @author w106
 *
 * @version 1.0.0
 *
 * @since 2014-5-5 上午10:17:46
 */
public class Response {

    public static int HTTP_ERROR = -1;

    private String url;

    private int status = HTTP_ERROR;

    private String response = "";

    private String charset;

    private final Map<String, List<String>> headers = new HashMap<String, List<String>>();

    /**
     * json反序列号需要用到.
     */
    public Response() {

    }

    public Response(String requrl) {
        url = requrl;
    }

    /**
     * http头信息.
     * @param key
     * @param value
     */
    public void addHead(String key, String value) {
        if (headers.containsKey(key)) {
            headers.get(key).add(value);
        } else {
            List<String> v = new ArrayList<String>();
            v.add(value);
            headers.put(key, v);
        }
    }

    /**
     * 获取指定的http头.
     * @param key
     * @return
     */
    public List<String> getHead(String key) {
        if (headers.containsKey(key)) {
            return headers.get(key);
        } else {
            return new ArrayList<String>();
        }
    }

    /**
     * 所有的http头信息.
     * @return
     */
    public Map<String, List<String>> getAllHead() {
        return headers;
    }

    /**
     * 状态.
     * @return
     */
    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getResponse() {
        return response;
    }

    public void setResponse(String response) {
        this.response = response;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getCharset() {
        return charset;
    }

    public void setCharset(String charset) {
        this.charset = charset;
    }

}
